package com.jianyun.jyzs.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.jianyun.jyzs.R;


public class CannotForwardMessageDialog extends AlertDialog {

    private Context context;
    private OnPromptButtonClickedListener buttonClickedListener;

    public CannotForwardMessageDialog(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.rce_dialog_cannot_forward, null);
        TextView cancelTextView = (TextView) view.findViewById(R.id.tv_cancel);
        TextView sureTextView = (TextView) view.findViewById(R.id.tv_sure);


        cancelTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (buttonClickedListener != null) {
                    buttonClickedListener.onNegativeButtonClicked();
                }
                dismiss();
            }
        });

        sureTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (buttonClickedListener != null) {
                    buttonClickedListener.onPositiveButtonClicked();
                    dismiss();
                }
                dismiss();
            }
        });

        setContentView(view);
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = ((WindowManager) (context.getSystemService(Context.WINDOW_SERVICE))).getDefaultDisplay().getWidth()
                - 2 * (int) context.getResources().getDimension(R.dimen.rce_dimen_size_40);

        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(layoutParams);
    }


    public OnPromptButtonClickedListener getButtonClickedListener() {
        return buttonClickedListener;
    }

    public void setButtonClickedListener(OnPromptButtonClickedListener buttonClickedListener) {
        this.buttonClickedListener = buttonClickedListener;
    }


    public interface OnPromptButtonClickedListener {
        void onPositiveButtonClicked();

        void onNegativeButtonClicked();
    }

}
